package Facade;

import Enumeration.ParserNames;
import GUI.AObserver;
import GUI.GUI;
import Parser.CreatorParser;
import GUI.Subject;
import Parser.ACreatorParser;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * @author Martin
 * @version 1.0
 * @created 14-III-2012 13:12:29
 */
public class Facade {

    public ACreatorParser creatorParser;
    public Subject subject;

    public Facade() {
        //nastaveni UIManager
        try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(GUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        create();
    }

    /**
     * start aplikace
     * - vola start gui
     * - start parseru, poskytuje enum ParserData
     */
    private void create() {
        ParserData pd =new ParserData("CHMI","Lužická Nisa","Liberec", "http://hydro.chmi.cz/hpps/hpps_prfdata.php?seq=2497645");
        creatorParser = new CreatorParser();
        AObserver gui = new GUI(this);
        creatorParser.addObserver(gui);    //pridame posluchace jako guicko
        
        //parsujeme
        creatorParser.createParser(pd, ParserNames.CHMI_flow_parser);            
        
    }
    public void end() {
        creatorParser.endAll();
    }
}